{extend name='../../admin/view/table'}

{block name="button"}
<!--{if auth("add")}-->
<!--<button data-modal='{:url("add")}' data-title="添加飞手" class='layui-btn layui-btn-sm layui-btn-primary'>添加飞手</button>-->
<!--{/if}-->
{/block}

{block name="content"}
<div class="think-box-shadow">
    {include file='pilot/index_search'}
    <table id="PilotTable" data-url="{:request()->url()}" data-target-search="form.form-search"></table>
</div>
{/block}

{block name='script'}
<script>
    $(function () {
        $('#PilotTable').layTable({
            even: true, height: 'full',
            sort: {field: 'id', type: 'desc'},
            cols: [[
                {checkbox: true},
                {field: 'id', title: 'ID', width: 80, sort: true, align: 'center'},
                // {field: 'sort', title: '排序', width: 100, align: 'center', sort: false, templet: '#SortInputTpl'},
                {
                    field: 'avatar', title: '头像', width: 60, align: 'center', templet: function (d) {
                        if (!d.avatar) return '-';
                        return layui.laytpl('<div class=" headimg-ss shadow-inset margin-0" data-tips-image data-tips-hover data-lazy-src="{{d.avatar}}"></div>').render(d);
                    }
                },
                {field: 'nickname', title: '用户昵称', minWidth: 100},
                {field: 'realname', title: '真实姓名', minWidth: 100},
                {field: 'phone', title: '联系电话', minWidth: 100},
                {field: 'balance', title: '余额', minWidth: 100},
                {field: 'status', title: '状态', width: 120, align: 'center', templet: '#StatusSwitchTpl'},
                {field: 'create_at', title: '创建时间', width: 180, align: 'center'},
                {toolbar: '#toolbar', title: '操作面板', align: 'left', minWidth: 120,  fixed: 'right'}
            ]]
        });

        // 数据状态切换操作
        layui.form.on('switch(StatusSwitch)', function (obj) {
            var data = {id: obj.value, status: obj.elem.checked > 0 ? 1 : 0};
            $.form.load("{:url('state')}", data, 'post', function (ret) {
                if (ret.code < 1) $.msg.error(ret.info, 3, function () {
                    $('#BaseTable').trigger('reload');
                });
                return false;
            }, false);
        });
    });
</script>


<!-- 列表排序权重模板 -->
<script type="text/html" id="SortInputTpl">
    <input type="number" min="0" data-blur-number="0" data-action-blur="{:sysuri()}" data-value="id#{{d.id}};action#sort;sort#{value}" data-loading="false" value="{{d.sort}}" class="layui-input text-center">
</script>

<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTpl">
    <!--{if auth("state")}-->
    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="已启用|已禁用" lay-filter="StatusSwitch" {{-d.status>0?'checked':''}}>
    <!--{else}-->
    {{-d.status ? '<b class="color-green">已启用</b>' : '<b class="color-red">已禁用</b>'}}
    <!--{/if}-->
</script>

<!-- 数据操作工具条模板 -->
<script type="text/html" id="toolbar">
    <!--{if auth('detail')}-->
    <a class="layui-btn layui-btn-sm layui-btn-primary" data-title="飞手详情" data-modal='{:url("detail")}?id={{d.id}}'>详 情</a>
    <!--{/if}-->

    <!--{if auth('edit')}-->
    <a class="layui-btn layui-btn-primary layui-btn-sm" data-event-dbclick data-title="编辑数据" data-modal='{:url("edit")}?id={{d.id}}'>编 辑</a>
    <!--{/if}-->

    <!--{if auth('remove')}-->
<!--    <a data-action='{:url("remove")}' data-value="id#{{d.id}}" data-confirm="确认要删除这条记录吗？" class="layui-btn layui-btn-sm layui-btn-danger">删 除</a>-->
    <!--{/if}-->
</script>
{/block}